package com.yupi.yuapiclientsdk.client;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.json.JSONUtil;
import com.yupi.yuapiclientsdk.model.User;

import java.nio.charset.StandardCharsets;

/**
 * @author lkc
 * @version 1.0
 */
public class NameApiClient extends YuApiClient{

    public NameApiClient(String accessKey,String secretKey){
        super(accessKey,secretKey);
    }

    public String getUsername(User user) {
        String json = JSONUtil.toJsonStr(user);
        HttpResponse httpResponse = HttpRequest.post(GATEWAY_HOST+"/api/interface/name/user")
                .charset(StandardCharsets.UTF_8) //防止中文乱码
                .addHeaders(getHeaderMap(json))
                .body(json)
                .execute();
        return httpResponse.body();
    }
}
